<?php
// +----------------------------------------------------------------------
// | 店铺账单
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;

class ShopBill extends Model
{
	
	//账单 - 加
	public static function income($title,$shop_id,$category,$type,$number,$link_id=0,$balance=0,$mark = '',$brokerage=0,$status=1)
    {
    	if(!$number || $number <= 0) return true;
		$pm = 1;
        return self::create(compact(
        	'title','shop_id','link_id','category','type','number','balance','mark','status','pm','brokerage'
		));
    }
	
	//账单 - 减
    public static function expend($title,$shop_id,$category,$type,$number,$link_id= 0,$balance=0,$mark = '',$brokerage=0,$status=1)
    {
    	if(!$number || $number <= 0) return true;
		$pm = 0;
        return self::create(compact(
        	'title','shop_id','link_id','category','type','number','balance','mark','status','pm','brokerage'
		));
    }
    
     /**
     * 积分/佣金 使用记录
     * @param $uid
     */
    public static function billList($shopId, $category='integral')
    {
    	$model = self::where('shop_id',$shopId);
		$model = $model->where('status',1);
		if( $category !=='*' ){
			$model = $model->where('category','in',$category);
		}
		$model = $model->field('id,link_id,title,pm,add_time,number,brokerage,mark');
		$model = $model->order('add_time','desc');
		$model = $model->page(input('pageIndex') ?: 1,input('pageSize') ?: 20);
		$list = $model->select()->toArray();
        foreach ($list as &$v){
            $v['add_time'] = date('Y.m.d H:i',strtotime($v['add_time']) );
            $v['number'] = floatval($v['number']);
            $v['brokerage'] = floatval($v['brokerage']);
        }
        return $list;
    }
    
	
}
